﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zeus.Thunder.Core;

namespace SharpTrainer.Linq
{
    class SubQueryTest : ITestCase
    {
        public void Run()
        {
            string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };

            Console.WriteLine("Using Chaining Lambda:");
            IEnumerable<string> query1 = names
                .Where(n => n.Length == names.OrderBy(n2 => n2.Length)
                .Select(n2 => n2.Length).First());
            Display(query1);

            Console.WriteLine("-------------------------------------------");

            IEnumerable<string> query2 =
                from n in names
                where n.Length == (from n2 in names orderby n2.Length select n2.Length).First()
                select n;
            Display(query2);
        }

        private void Display(IEnumerable<string> query)
        {
            foreach (string name in query)
                Console.WriteLine(name);
        }
    }
}
